package io.gitee.yth.design.pattern.test.core.pattern.behavioral.observer.chman;

import io.gitee.yth.design.pattern.test.core.pattern.behavioral.observer.IObserver;
import io.gitee.yth.design.pattern.test.core.pattern.behavioral.observer.ISubject;

/**
 * 与ChangeManager协调合作的subject抽象类
 *
 * @author yth
 * @since 2023-04-30-16:21
 */
public abstract class AbstractSubjectColleague implements ISubject {

    private final IChangeManager changeManager = ChangeManager.getInstance();

    @Override
    public void attach(IObserver observer) {
        changeManager.register(this, observer);
    }

    @Override
    public void detach(IObserver observer) {
        changeManager.unregister(this, observer);
    }

    @Override
    public void notifyObservers() {
        changeManager.notifyObservers(this);
    }

}
